﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Tools;
using Wp.DAL;

namespace Wp.BLL
{
    /// <summary>
    /// Summary description for Per_ActionsRoles
    /// </summary>
    public class TblAlbumManager : TblAlbumManagerBase
    {
        public TblAlbumManager()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public static TblAlbumManager CreateInstant()
        {
            return new TblAlbumManager();
        }
        public int InsertAlbum(string name, string textid, int imageurl)
        {
            try
            {
                TblAlbumEntity item = new TblAlbumEntity();
                item.Id = 0;
                if (textid == "")
                {
                    item.TextId = GetUniqueTextIdFromUnicodeText(name);
                }
                item.Name = name;
                item.ImageUrl = "";
                item.CreatedBy = HttpContext.Current.User.Identity.Name;
                item.CreatedDate = DateTime.Now;
                item.ModifiedBy = HttpContext.Current.User.Identity.Name;
                item.ModifiedDate = DateTime.Now;
                item.DisplayOrder = 1;
                TblAlbumManager.CreateInstant().InsertUpdate(item);
                return 1;
            }
            catch
            {
                return -1;
            }

        }
        public string GetUniqueTextIdFromUnicodeText(string UnicodeText)
        {
            string strSql = @"  SELECT TextId FROM TblAlbum tn
                                WHERE tn.TextId=@TextId";
            string textId = WebUtility.GetUniqueTextIdFromUnicodeText(UnicodeText, "@TextId", strSql
                , SqlHelper.WpConnectString, 255);
            return textId;
        }
    }
}
